﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;

namespace OpenPhotoAlbum.Controls.PhotoProcessors
{
	public class Convax : Offset
	{
		public override void ConfigureOffsetMatrix(Point[,] offsetMatrix, int width, int height)
		{
			int centerX = width / 2;
			int centerY = height / 2;
			double maxDistance = Math.Sqrt(centerX * centerX + centerY * centerY);
			for (int y = 0; y < height; y++)
			{
				for (int x = 0; x < width; x++)
				{
					double currentDistance = Math.Sqrt((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY));
					double factor = currentDistance / maxDistance;
					offsetMatrix[y, x] = new Point(
						Convert.ToInt32(x * factor + centerX * (1 - factor)),
						Convert.ToInt32(y * factor + centerY * (1 - factor)));
				}
			}
		}
	}
}
